package entities;

/**
 * A student is a person who has interacted with the system with the goal of
 * applying for a loan. Student's have loans, as well a info pertaining to their
 * schooling
 * 
 * @author gke703
 */
public class Student extends Person {

	/** name of the academic institution which the student is enrolled at */
	private String enrolledInstitution;

	/** True if student is currently a Canadian citizen, false otherwise */
	private boolean isCitizen;

	/** allowed values for the marital status of the student */
	public enum maritalStatuses {
		SINGLE, MARRIED, COMMONLAW
	};

	/** the marital status of the student */
	private maritalStatuses maritalStatus;

	/** allowed values for level of education */
	public enum education {
		DEGREE, DIPLOMA, HIGH_SCHOOL, NONE
	};

	/** level of education achieved by student's father */
	private education fatherEducation;

	/** level of education achieved by student's mother */
	private education motherEducation;

	/** student's social insurance number, must be 9 digits */
	private String SIN;

	/** Students have a FinancialInfo, maintaining their financial information */
	private FinancialInfo finances;

	/** Students can take out a loan */
	private Loan loan;

	/** The student's member's password */
	private String password;

	/** True if the students payment plan is created; false otherwise */
	private boolean paymentPlanCreated;

	/** The student's payment plan */
	private PaymentPlan paymentPlan;

	/**
	 * calls super constructor, initalizes attributes
	 * 
	 * @param myid
	 *            , int unique client id
	 * @param pd
	 *            , String representation of student's password
	 */
	public Student(int myid, String pd) {
		super(myid);
		enrolledInstitution = null;
		isCitizen = true; // assume student is a citizen to start
		maritalStatus = maritalStatuses.SINGLE;
		motherEducation = education.NONE;
		fatherEducation = education.NONE;
		SIN = null;
		finances = null;
		loan = null;
		password = pd;
		paymentPlanCreated = false;
	}

	/**
	 * accessor for currently enrolled institution
	 * 
	 * @return String, name of institution student is enrolled at
	 */
	public String getInstitution() {

		return enrolledInstitution;
	}

	/**
	 * mutator for currently enrolled institution
	 * 
	 * @param mySchool
	 *            String, currently enrolled school
	 */
	public void setInstitution(String mySchool) {

		enrolledInstitution = mySchool;
	}

	/**
	 * Determines whether or not student is a Canadian citizen
	 * 
	 * @return bool, true is student is a Canadian citizen, false otherwise
	 */
	public boolean getIsCitizen() {
		return isCitizen;
	}

	/**
	 * set whether or not Student is a Canadian Citizen
	 * 
	 * @Param myIsCitizen, bool true is student is a Canadian citizen, false
	 *        otherwise
	 */
	public void setCitizenship(boolean myIsCitizen) {
		isCitizen = myIsCitizen;
	}

	/**
	 * returns the current marital status of the sudent
	 * 
	 * @return maritalStatuses, can be either SINGLE, MARRIED, or COMMONLAW
	 */
	public maritalStatuses getMaritalStatus() {
		return maritalStatus;
	}

	/**
	 * mutator for student's marital status
	 * 
	 * @param myMaritalStatus
	 *            , must be either SINGLE, MARRIED, or COMMONLAW
	 */
	public void setMaritalStatus(maritalStatuses myMaritalStatus) {
		maritalStatus = myMaritalStatus;
	}

	/**
	 * Accessor for level of education achieved by student's father
	 * 
	 * @return education, can be only a value set by enum type education
	 */
	public education getFatherEducation() {
		return fatherEducation;
	}

	/**
	 * Mutator for level of education achieved by students father
	 * 
	 * @param myEducation
	 *            , can be only a value set by enum type education
	 */
	public void setFatherEducation(education myEducation) {
		fatherEducation = myEducation;
	}

	/**
	 * Accessor for level of education achieved by student's mother
	 * 
	 * @return education, can be only a value set by enum type education
	 */
	public education getMotherEducation() {
		return motherEducation;
	}

	/**
	 * Mutator for level of education achieved by student's mother
	 * 
	 * @param myEducation
	 *            , can be only a value set by enum type education
	 */
	public void setMotherEducation(education myEducation) {
		motherEducation = myEducation;
	}

	/**
	 * accessor for social insurance number
	 * 
	 * @return String, 9-digit social insurance number
	 */
	public String getSIN() {
		return SIN;
	}

	/**
	 * mutator for social insurance number
	 * 
	 * @param mySIN
	 *            new social insurance number. Must be a String of exactly 9
	 *            digits
	 * @throws RuntimeException
	 *             thrown if new SIN is not valid
	 */
	public void setSIN(String mySIN) {
		// check if new sin is valid
		if (mySIN.length() != 9) {
			throw new RuntimeException("SIN number must be 9 digits long");
		}

		char[] charSIN = mySIN.toCharArray();

		for (int i = 0; i < mySIN.length(); i++) {
			if (!Character.isDigit(charSIN[i])) {
				throw new RuntimeException("SIN number must be all digits");
			}
		}

		SIN = mySIN;

	}

	/**
	 * accessor for Student's financial information
	 * 
	 * @return FinancialInfo, student's financial information
	 */
	public FinancialInfo getFinances() {
		return finances;
	}

	/**
	 * mutator for Student's financial information
	 * 
	 * @param myFinances
	 *            ,
	 */
	public void setFinances(FinancialInfo myFinances) {

		finances = myFinances;
	}

	/**
	 * Accessor for student loan
	 * 
	 * @return Loan applied for by student
	 */
	public Loan getLoan() {
		return loan;
	}

	/**
	 * sets loan taken out by Student
	 * 
	 * @param myLoan
	 *            , Loan to be added
	 */
	public void setLoan(Loan myLoan) {
		loan = myLoan;
	}

	/**
	 * 
	 * @return the password for this employee
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Sets that a payment plan has been created or not
	 * 
	 * @param b
	 *            true if payment plan is created; false otherwise
	 * 
	 */
	public void setPaymentPlanCreated(boolean b) {
		paymentPlanCreated = b;
	}

	/**
	 * Gets whether payment plan has been created for the student or not
	 * 
	 * @return true if payment plan is created; false otherwise
	 */
	public boolean getPaymentPlanCreated() {
		return paymentPlanCreated;
	}

	/**
	 * Sets the payment plan for the student
	 * 
	 * @param p
	 *            payment plan set to the student
	 */
	public void setPaymentPlan(PaymentPlan p) {
		paymentPlan = p;
	}

	/**
	 * Gets the payment plan for the student
	 * 
	 * @return PaymentPlan of the student
	 */
	public PaymentPlan getPaymentPlan() {
		return paymentPlan;
	}

	/**
	 * regression tests
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Student myStudent = new Student(0, "");

		if (myStudent.getInstitution() != null) {
			System.out.println("");
		}

		myStudent.setInstitution("U of S");
		if (myStudent.getInstitution() != "U of S") {
			System.out.println("problem storing institution");
		}

		if (!myStudent.getIsCitizen()) {
			System.out.println("problem initializing citizenship");
		}

		myStudent.setCitizenship(false);
		if (myStudent.getIsCitizen()) {
			System.out.println("problem changing citisenship status");
		}

		if (myStudent.getMaritalStatus() != maritalStatuses.SINGLE) {
			System.out.println("problem initializing marital status");
		}

		myStudent.setMaritalStatus(maritalStatuses.MARRIED);
		if (myStudent.getMaritalStatus() != maritalStatuses.MARRIED) {
			System.out.println("problem changing marital status");
		}

		if (myStudent.getFatherEducation() != education.NONE) {
			System.out.println("problem initializing father's education");
		}

		myStudent.setFatherEducation(education.DEGREE);
		if (myStudent.getFatherEducation() != education.DEGREE) {
			System.out.println("problem changing father's education");
		}

		if (myStudent.getMotherEducation() != education.NONE) {
			System.out.println("problem initializing mother's education");
		}

		myStudent.setMotherEducation(education.HIGH_SCHOOL);
		if (myStudent.getMotherEducation() != education.HIGH_SCHOOL) {
			System.out.println("problem changing mother's education");
		}

		if (myStudent.getSIN() != null) {
			System.out.println("problem initializing SIN");
		}

		try {
			myStudent.setSIN("1231231234");
		} catch (RuntimeException e) {
			// System.out.println(e);
		}

		try {
			myStudent.setSIN("123123d23");
		} catch (RuntimeException e) {
			// System.out.println(e);
		}

		if (myStudent.getSIN() != null) {
			System.out
					.println("problem not letting SIN become an invalid number");
		}

		myStudent.setSIN("123123123");
		if (myStudent.getSIN() != "123123123") {
			System.out.println("problem changing SIN");
		}

		FinancialInfo myFinances = new FinancialInfo();
		myStudent.setFinances(myFinances);

		if (myStudent.getFinances() != myFinances) {
			System.out.println("problem retrieving financial information");
		}

		if (myStudent.getLoan() != null) {
			System.out.println("problem initializing loan");
		}

		Loan myloan = new Loan(myStudent);
		myStudent.setLoan(myloan);

		if (myStudent.getLoan() != myloan) {
			System.out.println("problem changing loan");
		}

	}

}
